package medium

import (
	. "GoLeetcode/common"
)

/*
时间复杂度:O(N)
空间复杂度:O(1)


*/

func maxSatisfied(customers []int, grumpy []int, minutes int) int {
	count := 0
	for i, v := range customers {
		if grumpy[i] == 0 {
			count += v
		}
	}
	m := Min(minutes, len(customers))
	for i := 0; i < m; i++ {
		if grumpy[i] == 1 {
			count += customers[i]
		}
	}

	ans := count
	for i := m; i < len(customers); i++ {
		if grumpy[i] == 1 {
			count += customers[i]
		}
		if grumpy[i-m] == 1 {
			count -= customers[i-m]
		}
		ans = Max(ans, count)
	}
	return ans
}
